//
//  HomeViewController.swift
//  InternshipGo
//
//  Created by zhujinhui on 15/12/10.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit

class HomeViewController: IGViewController ,UITableViewDelegate,UITableViewDataSource{
    
    @IBOutlet weak var tableView: UITableView!
    
    var data =  ["宝宝0","宝宝1","宝宝2","宝宝3","宝宝4","宝宝5","宝宝6","宝宝7","宝宝8","宝宝9","宝宝10","宝宝11"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "首页";
        tableView.allowsSelection = false
        
        let image = UIImage.init(named: "nav_but_add")
        let button = UIButton.init(frame: CGRectMake(0, 0, 50, 50))
        button.setImage(image, forState: UIControlState.Normal)

        let rightBarButtonItem = UIBarButtonItem.init(customView: button)
        self.navigationItem.rightBarButtonItem = rightBarButtonItem;
        
        self .doServiceWithName("====")

    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
//        self.tabBarController?.tabBar.hidden = false
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    
    //绘制cell
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier("DynamicState");
        if(cell == nil){
            cell = LatestTrendstCell.loadFromXib()
        }
        let tempCell = cell as! LatestTrendstCell
        tempCell.doneTextDidClickedBlock = {(text)->Void in
            let dynamicViewModel = DynamicDetailViewModel.init()
            self.hidesBottomBarWhenPushed = true
            Route.shareRoute.startViewControllerWithViewModel(self, toViewModel: dynamicViewModel)
        }
        
        tempCell.imageDidClickedBlock = {(text)->Void in
            let displayImageViewModel = DisplayImageViewModel.init()
            let imageName = "nav_but_add"
            displayImageViewModel.images = [imageName,imageName]
            self.hidesBottomBarWhenPushed = true
            Route.shareRoute.startViewControllerWithViewModel(self, toViewModel: displayImageViewModel)
        }

        return cell!
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
        return 210
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        

    }

    

}
